% This script is to validate the real-time calculator

%load the Jicamarca - Piura magnetic data for Sep 26, 2011

jic = load('/data/backup/mnair/real_time_model/Jic-Piu_2011_09_26.txt');
fday = datenum(jic(:,3),jic(:,2),jic(:,1),jic(:,4),jic(:,5),0);

% remove the daily variation by fitting a spline
b1 = min(fday) :(2/24): max(fday);
sp=spline(b1,jic(:,7)'/spline(b1,eye(length(b1)),fday));
v = ppval(fday,sp);


% get the ppefm data for the same day at longitude -77
[fday2,pp2] = getppefmL(2011,09,26,1,-77);

%plot data
plot(fday,jic(:,7)-v,'r');
hold on;
plot(fday2,pp2*100);
set(gca,'FontSize',16);
axis([datenum(2011,09,26,12,0,0) datenum(2011,09,26,24,0,0) -inf inf]);
xlabel('UT');
legend('JIC-PIU \Delta H','PPEFM mV/m*100');
title('Observed EEF (proxy) versus predictied  at Jicamarca for Sep 26, 2011');
datetick('x','keeplimits');

% The above day uses OMNI data base
saveas(gcf, '/data/backup/mnair/real_time_model/Jic-Piu_2011_09_26_pred.fig','fig');

% Not validating the PPEFM for real-time model. Today (May 21, 2012), the
% latest OMNI data was April 9. So dates after that uses ACE real-time
% data. It is important to validate this separately because of the
% "flat-delay" approach I use for propagation delay correction. According
% to WDC Kyoto, The sum Ap for 20120423 was 26 and the same for 20120424
% 41. Using these days 

% load Jicamarca - PIU data

jic = load('/data/backup/mnair/real_time_model/Jic-Piu_2012_April_23_24.txt')
fday = datenum(jic(:,3),jic(:,2),jic(:,1),jic(:,4),jic(:,5),0);

% remove the daily variation by fitting a spline
b1 = min(fday) :(2/24): max(fday);
sp=spline(b1,jic(:,7)'/spline(b1,eye(length(b1)),fday));
v = ppval(fday,sp);

% get ppefm for the same days at Jicamarca
[fday2,pp2] = getppefmL(2012,04,23,2,-77);


%plot data
plot(fday,jic(:,7)-v,'r');
hold on;
plot(fday2,pp2*100);
set(gca,'FontSize',16);
%axis([datenum(2012,09,26,12,0,0) datenum(2011,09,26,24,0,0) -inf inf]);
xlabel('UT');
legend('JIC-PIU \Delta H','PPEFM mV/m*100');
title('Observed EEF (proxy) versus predictied  at Jicamarca for April 23-24, 2012');
datetick('x','keeplimits');

% The above day uses OMNI data base
saveas(gcf, '/data/backup/mnair/real_time_model/Jic-Piu_2012_April_23_24.fig','fig');

% Comparing the model with Jicamarca ISR data for August 5-6 (Ap 42, 31)

jic1 = load('/data/backup/mnair/real_time_model/ISR_drift_Aug_5_2011.txt');
jic2 = load('/data/backup/mnair/real_time_model/ISR_drift_Aug_6_2011.txt');




